//
//  JQUserChangeNameVC.m
//  JQLive
//
//  Created by Bruce on 2020/8/18.
//  Copyright © 2020 mlkq. All rights reserved.
//

#import "JQUserChangeNameVC.h"
#import "UIView+Extension.h"
#import "JQMineProfileHeadCell.h"
#import "JQMineProfileCell.h"
#import "JQUserChangePwdVerificationVC.h"

@interface JQUserChangeNameVC ()<UITextFieldDelegate>

@property (nonatomic, strong) UIButton *verificationBottomLoginBtn;// 底部登录

@property (nonatomic, strong) UITextField *verificationPhoneTextField; // 验证码登录手机号
@property (nonatomic, strong) UITextField *verificationVerfiTextField;// 验证码登录 验证码
@property (nonatomic, strong) UIButton *verificationBtn;
@property (nonatomic, strong) CAGradientLayer *verificationGl;

@end

@implementation JQUserChangeNameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改昵称";
    [self addTopView];
    [self addNavBar];
    [self addView];
}
- (void)addNavBar{
    MY_WEAK;
    UILabel *titleLb = [[UILabel alloc] init];
    [self.view addSubview:titleLb];
    [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.size.mas_equalTo(CGSizeMake(145, 25));
        make.centerX.mas_equalTo(strongSelf.view);
        make.top.mas_equalTo(strongSelf.view.mas_top).offset(44);
    }];
    titleLb.textColor = [UIColor whiteColor];
    titleLb.font = [UIFont systemFontOfSize:18];
    titleLb.text = self.title;//@"修改密码";
    titleLb.textAlignment = NSTextAlignmentCenter;
    
    
    // 返回
    UIButton *backBtn = [[UIButton alloc] init];
    [backBtn setImage:[UIImage svgImageNamed:@"nav_back" size:CGSizeMake(15, 15)] forState:UIControlStateNormal];
    [self.view addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.view.mas_left).offset(18);
        make.centerY.mas_equalTo(titleLb);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [backBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    // rightBtn
    UIButton *rightBtn = [[UIButton alloc] init];
    [self.view addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.right.mas_equalTo(strongSelf.view.mas_right).offset(-18);
        make.centerY.mas_equalTo(titleLb);
        make.size.mas_equalTo(CGSizeMake(49, 22));
    }];
    [rightBtn addTapBlock:^(UIButton * _Nonnull btn) {
        // 保存接口
        
//        JQUserChangePwdVerificationVC
        [self.navigationController pushViewController:[[JQUserChangePwdVerificationVC alloc] init] animated:YES];
    }];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
}
- (void)addTopView{
    UIView *topView = [[UIView alloc] init];
    [self.view addSubview:topView];
    topView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 109);


    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,SCREEN_WIDTH,109);
    gl.startPoint = CGPointMake(1, 0.5);
    gl.endPoint = CGPointMake(0, 0.51);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:17/255.0 green:0/255.0 blue:169/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:9/255.0 green:37/255.0 blue:215/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    [topView.layer addSublayer:gl];
    
//    [self.navigationController.navigationBar.layer addSublayer:gl];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

// tabview 加载
- (void)addView{
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    MY_WEAK;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.top.mas_equalTo(strongSelf.view.mas_top).offset(86);
        make.left.bottom.right.equalTo(strongSelf.view);
    }];
    [view layoutIfNeeded];
    view.backgroundColor = kColorWithHex(0xF2F4FC);
    [view round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    UITextField *verificationPhoneTextField = [[UITextField alloc] init];
   [view addSubview:verificationPhoneTextField];
   self.verificationPhoneTextField = verificationPhoneTextField;
   verificationPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
   verificationPhoneTextField.returnKeyType = UIReturnKeyNext;
   verificationPhoneTextField.delegate = self;
   [verificationPhoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.mas_equalTo(view.mas_top).offset(14);
       make.left.mas_equalTo(view.mas_left).offset(10);
       make.right.mas_equalTo(view.mas_right).offset(-10);
       make.height.mas_equalTo(@(40));
   }];
   [self setTextField:verificationPhoneTextField placeholder:@"起一个昵称特别短的名字"];
    [self addPwdIsSecretBtnWith:verificationPhoneTextField];
    
}
- (void)addPwdIsSecretBtnWith:(UITextField *)textField{
    UIView *rightBackGroundView = [[UIView alloc] init];
    [textField addSubview: rightBackGroundView];
    [rightBackGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(textField);
        make.width.mas_equalTo(@(44));
    }];
    
    
    UIButton *pwdIsSecretBtn = [[UIButton alloc] init];
    [textField addSubview: pwdIsSecretBtn];
//    self.pwdIsSecretBtn = pwdIsSecretBtn;
    [pwdIsSecretBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.mas_equalTo(verificationVerfiTextField.mas_right).offset(-13);
        make.right.top.bottom.mas_equalTo(textField);
        make.width.mas_equalTo(@(44));
    }];
    [pwdIsSecretBtn setImage:[UIImage svgImageNamed:@"right_delete" size:CGSizeMake(13, 13)] forState:UIControlStateNormal];
    
    [pwdIsSecretBtn addTapBlock:^(UIButton * _Nonnull btn) {
        textField.text = nil;
        
    }];
}
// textfield 自定义UI
- (void)setTextField:(UITextField *)textField placeholder:(NSString *)placeholder {
    textField.placeholder = [NSString
                             stringWithFormat:@"   %@", placeholder];
    textField.backgroundColor = [UIColor whiteColor];//kColorWithHex(0xF2F4FC);
    [textField layoutIfNeeded];
    [textField round:5 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
    
    [textField setValue:[NSNumber numberWithInt:10] forKey:@"paddingLeft"];
//    verificationTextField.tintColor = kColorWithHex(0x010192);
    textField.textColor = kColorWithHex(0x010192);
    textField.font = [UIFont systemFontOfSize:14];
    if (@available(iOS 13.0, *)){
        textField.attributedPlaceholder = [[NSAttributedString alloc]initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName:kColorWithHex(0xAAAAAA), NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    }else{
        [textField setValue:kColorWithHex(0xAAAAAA) forKeyPath:@"_placeholderLabel.textColor"];
        [textField setValue:[UIFont boldSystemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    }
}
#pragma mark - UITextDeleagte
- (void)textFieldDidEndEditing:(UITextField *)textField{
    [self textFieldDidChangeSelectionComond:textField];
}
// iOS13 系统才走的方法
- (void)textFieldDidChangeSelection:(UITextField *)textField{
    [self textFieldDidChangeSelectionComond:textField];
}
// 代理来监听textField输入字符变化
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (@available(iOS 13.0, *)) {
        
    }else{
        [self textFieldDidChangeSelectionComond:textField];
    }
    return YES;
}
// 监听textField 公用方法
- (void)textFieldDidChangeSelectionComond:(UITextField *)textField{
   
}
#pragma mark - InitNAV
///// 设置导航栏的背景图，默认为 NavBarBackgroundImage
- (nullable UIImage *)navigationBarBackgroundImage{
    //    return [UIImage new];
    return [UIImage svgImageNamed:@"mine_background" size:CGSizeMake(SCREEN_WIDTH, 215)];
#pragma mark - 设置 导航栏的背景图  效果
    //     return [UIImage imageNamed:@"home_background"]; //这里的timg就是那张叶子图
}

/// 设置当前导航栏的 barTintColor，默认为 NavBarBarTintColor
- (nullable UIColor *)navigationBarBarTintColor{
    return [UIColor clearColor];
#pragma mark - 设置 导航栏的背景 颜色
    //    return MYHome_backgroundColor;
}
// 系统状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}


@end
